/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Giaodien;
import conn.JavaConnectDb;
import java.sql.Connection;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import oracle.jdbc.OraclePreparedStatement;
import oracle.jdbc.OracleResultSet;
import net.proteanit.sql.DbUtils;
import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JOptionPane;
import java.lang.*;

import btnhom.Nentdc;
/**
 *
 * @author nhung
 */
public class Nen extends javax.swing.JFrame {

    Connection conn = JavaConnectDb.ConnectDb();
    OraclePreparedStatement pst;
    OracleResultSet rs;
    
    private int flag;
    /**
     * Creates new form Nen
     */
    public Nen() {
        initComponents();
        loadCB();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        txtManen = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtTennen = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtcapphat = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtchieudai = new javax.swing.JTextField();
        txtchieurong = new javax.swing.JTextField();
        cbMaloai = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbNen = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        btThem = new javax.swing.JButton();
        btXoa = new javax.swing.JButton();
        btSua = new javax.swing.JButton();
        btThoat = new javax.swing.JButton();
        btLuu = new javax.swing.JButton();
        btHuy = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
        jLabel1.setText("THONG TIN VE NEN");

        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 0, 153)));

        jLabel2.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
        jLabel2.setText("Ma nen");

        txtManen.setName("txtManen"); // NOI18N

        jLabel3.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
        jLabel3.setText("Ten nen");

        txtTennen.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        txtTennen.setName("txtTennen"); // NOI18N

        jLabel4.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
        jLabel4.setText("Cap phat");

        txtcapphat.setName("txtcapphat"); // NOI18N

        jLabel5.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
        jLabel5.setText("Chieu dai");

        jLabel6.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
        jLabel6.setText("Chieu rong");

        jLabel7.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
        jLabel7.setText("Ma Loai Nen");

        txtchieudai.setName("txtchieudai"); // NOI18N

        txtchieurong.setName("txtchieurong"); // NOI18N

        cbMaloai.setName("cbMaloai"); // NOI18N
        cbMaloai.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cbMaloaiMouseClicked(evt);
            }
        });

        jScrollPane1.setName("tbNen"); // NOI18N

        tbNen.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Ma_Nen", "Ten_Nen", "Chieu dai", "Chieu rong", "Cap phat", "Ma_Loai"
            }
        ));
        tbNen.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbNenMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tbNen);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 590, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtManen)
                    .addComponent(txtTennen)
                    .addComponent(txtcapphat, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtchieudai, javax.swing.GroupLayout.DEFAULT_SIZE, 184, Short.MAX_VALUE)
                    .addComponent(txtchieurong)
                    .addComponent(cbMaloai, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtManen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtchieudai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtTennen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtchieurong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE)
                    .addComponent(txtcapphat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cbMaloai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel2.setForeground(new java.awt.Color(0, 0, 255));

        btThem.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
        btThem.setForeground(new java.awt.Color(0, 0, 255));
        btThem.setText("Them");
        btThem.setName("tbThem"); // NOI18N
        btThem.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btThemMouseClicked(evt);
            }
        });

        btXoa.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
        btXoa.setForeground(new java.awt.Color(0, 0, 255));
        btXoa.setText("Xoa");
        btXoa.setName("btXoa"); // NOI18N
        btXoa.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btXoaMouseClicked(evt);
            }
        });

        btSua.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
        btSua.setForeground(new java.awt.Color(0, 0, 255));
        btSua.setText("Sua");
        btSua.setName("btSua"); // NOI18N
        btSua.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btSuaMouseClicked(evt);
            }
        });

        btThoat.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
        btThoat.setForeground(new java.awt.Color(0, 0, 255));
        btThoat.setText("Thoat");
        btThoat.setName("btThoat"); // NOI18N
        btThoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btThoatActionPerformed(evt);
            }
        });

        btLuu.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
        btLuu.setForeground(new java.awt.Color(0, 0, 255));
        btLuu.setText("Luu");
        btLuu.setName("btLuu"); // NOI18N
        btLuu.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btLuuMouseClicked(evt);
            }
        });

        btHuy.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
        btHuy.setForeground(new java.awt.Color(0, 0, 255));
        btHuy.setText("Huy");
        btHuy.setName("tbHuy"); // NOI18N
        btHuy.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btHuyMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btThem)
                .addGap(29, 29, 29)
                .addComponent(btXoa, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32)
                .addComponent(btSua, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(36, 36, 36)
                .addComponent(btThoat)
                .addGap(21, 21, 21)
                .addComponent(btLuu, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btHuy, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btThoat, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btLuu, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btHuy)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(btThem, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
                                .addComponent(btXoa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(btSua, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(58, 58, 58)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(258, 258, 258)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(42, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
 
 private void loadCB() {
    String sql = "select * from loainen_tdc";
    try{
         pst = (OraclePreparedStatement) conn.prepareStatement(sql);
         rs = (OracleResultSet) pst.executeQuery();
         while(rs.next())
         {
          this.cbMaloai.addItem(rs.getString("maloai_nen"));
         }
    } catch(Exception e)
    {
         JOptionPane.showMessageDialog(null, e, "Khong the ket noi server",1);
    }
}
private void loadNen()
    {
         try{
             flag=0;
             txtManen.setEditable(true);
             txtTennen.setEnabled(true);
             txtchieudai.setEnabled(true);
             txtchieurong.setEnabled(true);
             txtcapphat.setEnabled(true);
             OracleResultSet rs = new Nentdc().selectNen();
             tbNen.setModel(DbUtils.resultSetToTableModel(rs));
            
             btThem.setVisible(true);
             btXoa.setVisible(true);
             btSua.setVisible(true);
             btThoat.setVisible(true);
             btLuu.setVisible(true);
             btHuy.setVisible(true);  
         }catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        } 
    }
    private void btThemMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btThemMouseClicked
        flag=1;
        txtManen.setText(null);
        txtTennen.setText(null);
        txtchieudai.setText(null);
        txtchieurong.setText(null);
        txtcapphat.setText(null);
        btThem.setVisible(true);
        btXoa.setVisible(true);
        btSua.setVisible(true);
        btThoat.setVisible(true);
        btLuu.setVisible(true);
        btHuy.setVisible(true);
        txtManen.setEnabled(true);
    }//GEN-LAST:event_btThemMouseClicked

    private void btLuuMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btLuuMouseClicked
        if(txtManen.getText().equals("") || txtTennen.getText().equals("") || txtchieudai.getText().equals("") || 
        txtchieurong.getText().equals("") || txtcapphat.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Vui long thuc hien thao tac truoc khi luu");
        }
        else 
        {
        try{
            if(flag==1)
            {
            Nentdc insert = new Nentdc();
            insert.insertNen(txtManen.getText(), txtTennen.getText(), txtchieudai.getText(), 
            txtchieurong.getText(), txtcapphat.getText(), cbMaloai.getSelectedItem().toString());
            flag=0;
            }
            if(flag==2)
            {
            Nentdc update = new Nentdc();
            update.updateNen(txtManen.getText(), txtTennen.getText(), txtchieudai.getText(), 
            txtchieurong.getText(), txtcapphat.getText(), cbMaloai.getSelectedItem().toString());
            flag=0;
            }
        }catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, "Cap nhat khong thanh cong");
        }
        } 
    }//GEN-LAST:event_btLuuMouseClicked

    private void btThoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btThoatActionPerformed
        dispose();
        new Sub_main_QLTDC().setVisible(true);
    }//GEN-LAST:event_btThoatActionPerformed

    private void btXoaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btXoaMouseClicked
        if(txtManen.getText().equals("")){
        JOptionPane.showMessageDialog(null, "Vui long chon doi tuong de xoa");
        }
        else {
        int reply = JOptionPane.showConfirmDialog(null, "Ban co chac xoa khong ?", "Xac nhan xoa", JOptionPane.YES_NO_OPTION);
        if (reply == JOptionPane.YES_OPTION)
        {
             Nentdc delete = new Nentdc();
             delete.deleteNen(txtManen.getText());
        }
        }
    }//GEN-LAST:event_btXoaMouseClicked

    private void tbNenMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbNenMouseClicked
        DefaultTableModel model = (DefaultTableModel) tbNen.getModel();
        txtManen.setText((String) model.getValueAt(tbNen.getSelectedRow(), 0));
        txtTennen.setText((String) model.getValueAt(tbNen.getSelectedRow(), 1));
        txtchieudai.setText((String) model.getValueAt(tbNen.getSelectedRow(), 2));
        txtchieurong.setText((String) model.getValueAt(tbNen.getSelectedRow(), 3));
        txtcapphat.setText((String) model.getValueAt(tbNen.getSelectedRow(), 4));
        //cbMaloai.setText((String) model.getValueAt(tbNen.getSelectedRow(), 5))
    }//GEN-LAST:event_tbNenMouseClicked
   
    private void btSuaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btSuaMouseClicked
       txtTennen.setEditable(true);
       txtTennen.requestFocusInWindow();
       txtchieudai.requestFocusInWindow();
       txtchieurong.requestFocusInWindow();
       txtcapphat.requestFocusInWindow();
        if(txtManen.getText().equals("") || txtTennen.getText().equals("") || txtchieudai.getText().equals("")
                || txtchieurong.getText().equals("") || txtcapphat.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Vui long chon doi tuong de sua");
        }
        flag=2; 
        txtManen.setEnabled(false);
        btThem.setVisible(true);
        btXoa.setVisible(true);
        btSua.setVisible(true);
        btThoat.setVisible(true);
        btLuu.setVisible(true);
        btHuy.setVisible(true);
    }//GEN-LAST:event_btSuaMouseClicked

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        loadNen();
    }//GEN-LAST:event_formWindowActivated

    private void btHuyMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btHuyMouseClicked
        loadNen();
    }//GEN-LAST:event_btHuyMouseClicked

    private void cbMaloaiMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cbMaloaiMouseClicked

    }//GEN-LAST:event_cbMaloaiMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Nen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Nen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Nen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Nen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Nen().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btHuy;
    private javax.swing.JButton btLuu;
    private javax.swing.JButton btSua;
    private javax.swing.JButton btThem;
    private javax.swing.JButton btThoat;
    private javax.swing.JButton btXoa;
    private javax.swing.JComboBox cbMaloai;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tbNen;
    private javax.swing.JTextField txtManen;
    private javax.swing.JTextField txtTennen;
    private javax.swing.JTextField txtcapphat;
    private javax.swing.JTextField txtchieudai;
    private javax.swing.JTextField txtchieurong;
    // End of variables declaration//GEN-END:variables
}
